#include "error.h"
#include "ui_error.h"
#include <QDebug>

Error::Error(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Error)
{
    ui->setupUi(this);
}

Error::~Error()
{
    delete ui;
}

bool Error::m_IllegalCharCheck(QString name, QString data, int size)
{
    QString warn;

    if(size != data.count()){
        warn = "Size isn't ";
        warn += (size+48);
        warn += '!';
        m_ErrorPlay(name,warn);
        //qDebug()<<warn;
        return true;
    }

    for(int i = 0; i < data.count(); i++)
        if(data.at(i) < 48 || (data.at(i) > 57 && data.at(i) < 65) || (data.at(i) > 90 && data.at(i) < 97) || data.at(i) > 122){
            warn += "Illegal char '";
            warn += data.at(i);
            warn += "\'!";
            m_ErrorPlay(name,warn);
            return true;
        }
    return false;
}

void Error::m_Format(QByteArray *head,QString count,int size,char c)//追加到head里
{
    *head += count;
    for(int i=0;i<size-count.count();i++)
        *head += c;
}

void Error::m_ErrorPlay(QString error_name,QString error_describe)
{
     ui->lEerror_name->setText(error_name);
     ui->tEerror_describe->setText(error_describe);
     this->show();
}

